﻿using ADManage.api.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Claims;
using System.Threading.Tasks;
using System.Web.Http;
using XF.Common.Redis;
using XF.Meeting.Api.Models;
using XF.Meeting.Entity.CommonEntity;
using XF.Meeting.Entity.DTO;
using XF.Meeting.Entity.dbEntity;
using XF.Meeting.Entity.Query;
using XF.Meeting.Entity.View;
using XF.Sugar.IService;
using XF.Meeting.Api.Filters;
using XF.Meeting.Api.BPMService;
using System.Web;
using XF.Common;
using XF.Meeting.Api.Common;
using System.Text;
using System.Threading;
using UEntity.LogEntity;

namespace XF.Meeting.Api.Controllers
{
    public class MeetRoomController : BaseController
    {
        /// <summary>
        /// 添加会议室
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> AddMeetingRoom([FromBody] ObjBase<MeetingRoomOrder> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            entity.obj.AppointmentProcess = 1;
            entity.obj.StrategyState = 1;
            var (bResult, strError) = await service.AddMeetingRoom(entity.obj);

            if (bResult)
            {
                var res = new ResultBase<String>()
                {
                    data = "添加会议室成功",
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<String>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = strError,
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 根据会议室ID获取会议室信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetMeetingRoomByID([FromBody] ObjBase<MeetingRoomQuery> query)
        {

            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
         
            var info = await service.GetMeetingRoomByID(query.obj);

            if (info != null)
            {
                var res = new ResultBase<MeetingRoomOrder>()
                {
                    data = info,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<MeetingRoomOrder>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议室信息失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }



        /// <summary>
        /// 根据ID修改会议室信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> UpdateMeetingRoomByID([FromBody] ObjBase<MeetingRoomOrder> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            entity.obj.AppointmentProcess = 1;
            entity.obj.StrategyState = 1;
            var (bResult, strError) = await service.UpdateMeetingRoomByID(entity.obj);

            if (bResult)
            {
                var res = new ResultBase<String>()
                {
                    data = "修改会议室信息成功",
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<String>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = strError,
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 删除会议室
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> DeleteMeetingRoom([FromBody] ObjBase<MeetingRoomQuery> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var bResult = await service.DeleteMeetingRoom(entity.obj);

            if (bResult)
            {
                var res = new ResultBase<String>()
                {
                    data = "删除会议室成功",
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<String>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "删除会议室失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 会议纪要（手动创建）
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> MinutesOrder([FromBody] ObjBase<MeetingOrder> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            bool bResult = true;
            string strError = "";
            int idd = 0;


            (bResult, strError, idd) = await service.MinutesOrder(entity.obj);


            var url = "";
            if (bResult)
            {
                var res = new ResultBase<String>()
                {
                    data = "会议纪要创建成功",
                    success = true,
                    errormsg = "",
                    ProcessUrl = url
                };
                var data = new ObjBase<ResultBase<String>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = strError,
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 会议纪要附件
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IHttpActionResult> MinutesAnnexUpdate()
        {

            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            bool bResult = true;
            string strError = "";
            string url = "";
            string name = "";
            HttpFileCollection file = System.Web.HttpContext.Current.Request.Files;
            UpLoadEntity upLoadEntity = new UpLoadEntity();
            if (file.Count > 0)
            {
                UpLoad upLoad = new UpLoad();
                (bResult, strError, url, name) = await upLoad.FileUpload(file[0], "MinutesAnnex");
                upLoadEntity.name = name;
                upLoadEntity.url = url;
            }

            if (bResult)
            {

                var res = new ResultBase<UpLoadEntity>()
                {
                    data = upLoadEntity,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<UpLoadEntity>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "上传失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }







        }

        /// <summary>
        /// 会议室图片附件
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IHttpActionResult> MeetingRoomAnnex()
        {

            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            bool bResult = true;
            string strError = "";
            string url = "";
            string name = "";
            HttpFileCollection file = System.Web.HttpContext.Current.Request.Files;
            UpLoadEntity upLoadEntity = new UpLoadEntity();
            if (file.Count > 0)
            {
                UpLoad upLoad = new UpLoad();
                (bResult, strError, url, name) = await upLoad.FileUpload(file[0], "MeetingRoomImg");
                upLoadEntity.name = name;
                upLoadEntity.url = url;
            }

            if (bResult)
            {

                var res = new ResultBase<UpLoadEntity>()
                {
                    data = upLoadEntity,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<UpLoadEntity>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = strError,
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }







        }

        /// <summary>
        /// 系统设置附件
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> SystemAnnex()
        {

            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            bool bResult = true;
            string strError = "";
            string url = "";
            string name = "";
            HttpFileCollection file = System.Web.HttpContext.Current.Request.Files;
            UpLoadEntity upLoadEntity = new UpLoadEntity();
            if (file.Count > 0)
            {
                UpLoad upLoad = new UpLoad();
                (bResult, strError, url, name) = await upLoad.FileUpload(file[0], "System");
                upLoadEntity.name = name;
                upLoadEntity.url = url;
            }

            if (bResult)
            {

                var res = new ResultBase<UpLoadEntity>()
                {
                    data = upLoadEntity,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<UpLoadEntity>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = strError,
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }







        }

        /// <summary>
        /// 根据ID修改会议纪要
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> UpdateConferenceMinutes([FromBody] ObjBase<MeetingOrder> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var (bResult, strError) = await service.UpdateConferenceMinutes(entity.obj);
            var url = "";
            if (bResult)
            {
         
                var res = new ResultBase<string>()
                {
                    data = "修改会议纪要成功",
                    success = true,
                    errormsg = "",
                    ProcessUrl = url
                };
                var data = new ObjBase<ResultBase<string>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = strError,
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 根据会议ID获取会议纪要
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetCInfoMinutesByID([FromBody] ObjBase<CInfoQuery> query)
        {

            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);

            var info = await service.GetCInfoMinutesByID(query.obj);

            if (info != null)
            {
                var res = new ResultBase<MinutesInfoSingle>()
                {
                    data = info,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<MinutesInfoSingle>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议信息失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 根据查询关键字获取所有会议纪要
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetCInfoMinutesList([FromBody] ObjBase<CInfoQuery> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetCInfoMinutesList(query.obj);

            if (list != null)
            {
                var res = new ResultBase<PageList<MinutesList>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<PageList<MinutesList>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议纪要列表失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 根据查询关键字获取组织所有会议纪要
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetOrgMinutes([FromBody] ObjBase<CInfoQuery> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetOrgMinutes(query.obj);

            if (list != null)
            {
                var res = new ResultBase<PageList<MinutesList>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<PageList<MinutesList>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取组织会议纪要列表失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 会议预约
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> MeetingOrder([FromBody] ObjBase<MeetingOrder> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var wxtype = user.wxType;
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var (bResult, strError, meeetIDs, IsSendWX, IsSendBPM, CycleMeetType) = await service.MeetingOrder(user, entity.obj);
            CLogger.Info("插入返回进来了：：" + wxtype);
            var url = "";
            if (bResult &&  entity.obj.IsPushEntWechat)
            {
                foreach (var item in meeetIDs)
                {
                   var (calendarsResult,strerror, calendarsid) =  service.InsertCInfoToOrgcalendars(item);
                    if (calendarsResult)
                    {
                        WeChatHelper wx =   new WeChatHelper();
                        wx.InsertWechatSchedule(calendarsid);
                    }
                }
            }
            if (bResult)
            {
              
                    if (CycleMeetType == 0)
                    {
                        if (IsSendWX)
                        {

                            switch (wxtype)
                            {
                                case 1:
                                    var wx1 = new WeChatHelper();
                                    wx1.SendWxMssage(new CRoomPadQuery() { CInfoId = meeetIDs[0], type = 1 }, !IsSendWX);
                                    wx1.SendTPwdToCreator(new CRoomPadQuery() { CInfoId = meeetIDs[0], type = 1 }, false);
                                    break;
                                case 2:
                                    var wx2 = new WyChatHelper();
                                    wx2.SendWxMssage(new CRoomPadQuery() { CInfoId = meeetIDs[0], type = 1 }, !IsSendWX);
                                    wx2.SendTPwdToCreator(new CRoomPadQuery() { CInfoId = meeetIDs[0], type = 1 }, false);
                                    break;
                                default:
                                    var wx3 = new WeChatHelper();
                                    wx3.SendWxMssage(new CRoomPadQuery() { CInfoId = meeetIDs[0], type = 1 }, !IsSendWX);
                                    wx3.SendTPwdToCreator(new CRoomPadQuery() { CInfoId = meeetIDs[0], type = 1 }, false);
                                    break;
                            }


                        }
                       
                    }
                var res = new ResultBase<String>()
                {

                    data = "预约会议室成功",
                    success = true,
                    errormsg = "",
                    ProcessUrl = url
                };
                var data = new ObjBase<ResultBase<String>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "预约会议室失败",
                    errmsg = strError,
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 根据ID修改会议信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> UpdateConferenceInfo([FromBody] ObjBase<MeetingOrder> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var (bResult, strError, procInstID, IsSendWX, IsSendBPM) = await service.UpdateConferenceInfo(user, entity.obj);
            if(bResult)
            {
                var res = service.UpdateOrgcalendarsByCInfoID(entity.obj.ID);
                if (res.Result.Item3 > 0)
                {
                    WeChatHelper wx = new WeChatHelper();
                    wx.UpdateWechatSchedule(res.Result.Item3);
                }
              
            }
            
            if (bResult)
            {

                var res = new ResultBase<String>()
                {
                    data = "修改会议信息成功",
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<String>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = strError,
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 获取会议室及会议室会议信息  PC
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetMeetRoomAndInfo([FromBody] ObjBase<RoomQuery> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetMeetRoomAndInfo(query.obj);

            if (list != null)
            {
                var res = new ResultBase<MeetAndRoomInfo>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<MeetAndRoomInfo>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议室信息失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 获取会议室及会议室会议信息  PC(周视图)
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetMeetRoomAndInfoForWeek([FromBody] ObjBase<RoomQuery> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetMeetRoomAndInfoForWeek(query.obj);

            if (list != null)
            {
                var res = new ResultBase<PageList<MeetAndRoomInfoForWeek>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<PageList<MeetAndRoomInfoForWeek>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取周会议信息失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 获取会议室及会议室会议信息  Mobile
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IHttpActionResult> GetMeetRoomAndInfoForMobile([FromBody] ObjBase<RoomQuery> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetMeetRoomAndInfoForMobile(query.obj);

            if (list.List != null)
            {
                var res = new ResultBase<PageListMobile<MeetAndRoomInfoForMobile>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<PageListMobile<MeetAndRoomInfoForMobile>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议室信息失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 根据区域ID获取当前区域下所有会议室信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetMeetRoomByRID([FromBody] ObjBase<RoomQuery> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetCRoomByRID(query.obj);

            if (list != null)
            {
                var res = new ResultBase<PageList<MeetingRoomInfo>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<PageList<MeetingRoomInfo>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议室信息失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 根据区域ID集合获取当前区域下所有会议室信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetMeetRoomByRIDs([FromBody] ObjBase<RoomQuery> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetCRoomByRIDs(query.obj);

            if (list != null)
            {
                var res = new ResultBase<PageList<MeetingRoomInfo>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<PageList<MeetingRoomInfo>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议室信息失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 根据区域ID获取当前区域下所有会议室列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetCRoomInfoListByRID([FromBody] ObjBase<RoomQuery> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetCRoomInfoListByRID(query.obj);

            if (list != null)
            {
                var res = new ResultBase<PageList<MeetingRoomInfo>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<PageList<MeetingRoomInfo>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议室信息失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 根据区域ID获取当前区域下所有会议室信息(编辑回显)
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetMeetRoomByRIDForUpdate([FromBody] ObjBase<RoomQuery> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetCRoomByRIDForUpdate(query.obj);

            if (list != null)
            {
                var res = new ResultBase<PageList<MeetingRoomInfo>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<PageList<MeetingRoomInfo>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议室信息失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 根据查询关键字获取所有会议室信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetMeetRoomByKey([FromBody] ObjBase<RoomQuery> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetCRoomByKey(query.obj);

            if (list != null)
            {
                var res = new ResultBase<PageList<MeetingRoomInfo>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<PageList<MeetingRoomInfo>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议室信息失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 获取会议信息(我的创建)
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetMeetingInfo([FromBody] ObjBase<CInfoQuery> query)
        {
            PageList<MeetingInfo> list = new PageList<MeetingInfo>();
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            //query.obj.UserID = user.UserId;
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            //if (user.IsAdmin)
            //{
            //    list = await service.GetCInfoByAdmin(query.obj);
            //}
            //else
            //{
            list = await service.GetCInfoByUser(query.obj);
            //}


            if (list.List != null)
            {
                var res = new ResultBase<PageList<MeetingInfo>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<PageList<MeetingInfo>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议信息失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 根据会议ID获取会议信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetMeetingInfoByID([FromBody] ObjBase<CInfoQuery> query)
        {

            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);

            var info = await service.GetCInfoByID(query.obj);

            if (info != null)
            {
                var res = new ResultBase<MeetingInfoSingle>()
                {
                    data = info,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<MeetingInfoSingle>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议信息失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 根据会议ID修改会议信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> UpdateMeetingInfoByID([FromBody] ObjBase<MeetingOrder> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var bResult = await service.UpdateMeetingInfoByID(entity.obj);

            if (bResult)
            {
                var res = new ResultBase<String>()
                {
                    data = "修改会议信息成功",
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<String>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "修改会议信息失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// (参与会议)当前登录用户查看会议列表（创建，协调，主持，纪要，内部参会，转赠）
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetAllCInfoByUser([FromBody] ObjBase<CInfoQuery> query)
        {
            PageList<MeetingInfo> list = new PageList<MeetingInfo>();
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);

            list = await service.GetAllCInfoByUser(query.obj);



            if (list.List != null)
            {
                var res = new ResultBase<PageList<MeetingInfo>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<PageList<MeetingInfo>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议信息失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 会议转赠
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> TransferMeeting([FromBody] ObjBase<TransferMeeting> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var bResult = await service.TransferMeeting(entity.obj);
            if (bResult)
            {
                var res = service.UpdateOrgcalendarsByCInfoID(entity.obj.ID);
                if (res.Result.Item3 > 0)
                {
                    WeChatHelper wx = new WeChatHelper();
                    wx.UpdateWechatSchedule(res.Result.Item3);
                }

            }
            if (bResult)
            {
                var res = new ResultBase<String>()
                {
                    data = "转赠会议成功",
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<String>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "转赠会议失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 会议延长
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> ExtendMeeting([FromBody] ObjBase<ExtendMeeting> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            entity.obj.userId = user.UserId;
            var (bResult, strError) = await service.ExtendMeeting(entity.obj);
            if (bResult)
            {
                var res = service.UpdateOrgcalendarsByCInfoID(entity.obj.ID);
                if (res.Result.Item3 > 0)
                {
                    WeChatHelper wx = new WeChatHelper();
                    wx.UpdateWechatSchedule(res.Result.Item3);
                }

            }
            if (bResult)
            {
                var res = new ResultBase<String>()
                {
                    data = "延长会议成功",
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<String>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = strError,
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 会议取消
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> DeleteMeetingInfo([FromBody] ObjBase<TransferMeeting> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            entity.obj.UserID = user.UserId;
            var bResult = await service.DeleteMeetingInfo(entity.obj);
            if (bResult)
            {
                var res = service.deleteCInfoToOrgcalendars(entity.obj.ID);
                if (res.Result.Item3 > 0)
                {
                    WeChatHelper wx = new WeChatHelper();
                    wx.CancelWechatSchedule(res.Result.Item3);
                }

            }
            if (bResult)
            {
                switch (user.wxType)
                {
                    case 1:
                        var wx1 = new WeChatHelper();
                        wx1.SendChnnelMsg(entity.obj.ID);
                        break;
                    case 2:
                        var wx2 = new WyChatHelper();
                        wx2.SendChnnelMsg(entity.obj.ID);
                        break;
                    default:
                        var wx3 = new WeChatHelper();
                        wx3.SendChnnelMsg(entity.obj.ID);
                        break;
                }

                //BS_Service bS_Service = new BS_Service();
                //BPMDoInvalid bPMDoInvalid = new BPMDoInvalid();
                //var doInvalidResult = bS_Service.DoInvalid(bPMDoInvalid.bsid, bPMDoInvalid.btid, bPMDoInvalid.boid, bPMDoInvalid.userid, bPMDoInvalid.procInstID, bPMDoInvalid.invalidComment);
                var res = new ResultBase<String>()
                {
                    data = "取消会议成功",
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<String>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "取消会议失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 提前结束会议
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> UpdateMeetingEnd([FromBody] ObjBase<CInfoQuery> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            entity.obj.UserID = user.UserId;
            var bResult = await service.UpdateMeetingEnd(entity.obj);
            if (bResult)
            {
                var res = service.UpdateOrgcalendarsByCInfoID(entity.obj.CInfoID);
                if (res.Result.Item3 > 0)
                {
                    WeChatHelper wx = new WeChatHelper();
                    wx.UpdateWechatSchedule(res.Result.Item3);
                }

            }
            if (bResult)
            {
                //BS_Service bS_Service = new BS_Service();
                //BPMDoInvalid bPMDoInvalid = new BPMDoInvalid();
                //var doInvalidResult = bS_Service.DoInvalid(bPMDoInvalid.bsid, bPMDoInvalid.btid, bPMDoInvalid.boid, bPMDoInvalid.userid, bPMDoInvalid.procInstID, bPMDoInvalid.invalidComment);
                var res = new ResultBase<String>()
                {
                    data = "提前结束会议成功",
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<String>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "提前会议失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 添加会议设备
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> AddMeetingEquipment([FromBody] ObjBase<MeetingEquipment> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var (bResult, strError) = await service.AddMeetingEquipment(entity.obj);

            if (bResult)
            {
                var res = new ResultBase<String>()
                {
                    data = "添加会议设备成功",
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<String>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = strError,
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 删除会议设备
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> DeleteMeetingEquipment([FromBody] ObjBase<MeetingEquipment> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var bResult = await service.DeleteMeetingEquipment(entity.obj);

            if (bResult)
            {
                var res = new ResultBase<String>()
                {
                    data = "删除会议设备成功",
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<String>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "删除会议设备失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 根据ID修改会议设备名称
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> UpdateMeetingEquipment([FromBody] ObjBase<MeetingEquipment> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var (bResult, strError) = await service.UpdateMeetingEquipment(entity.obj);
            //string ServerPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
            if (bResult)
            {
                var res = new ResultBase<String>()
                {
                    data = "修改会议设备成功",
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<String>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = strError,
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 根据查询关键字获取所有会议设备信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetMeetingEquipment([FromBody] ObjBase<EquipmentQuery> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetMeetingEquipment(query.obj);

            if (list != null)
            {
                var res = new ResultBase<PageList<MeetingEquipment>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<PageList<MeetingEquipment>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议设备信息失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 获取会议须知
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetConferenceNotice()
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetConferenceNotice();

            if (list != null)
            {
                var res = new ResultBase<ConferenceNotice>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<ConferenceNotice>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议须知失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 根据ID修改会议须知
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> UpdateConferenceNotice([FromBody] ObjBase<ConferenceNotice> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var (bResult, strError) = await service.UpdateConferenceNotice(entity.obj);

            if (bResult)
            {
                var res = new ResultBase<String>()
                {
                    data = "修改会议须知成功",
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<String>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = strError,
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 会议审批
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> ApprovalMeeting([FromBody] ObjBase<ApprovalMeeting> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var bResult = await service.ApprovalMeeting(entity.obj);

            if (bResult)
            {
                //QuartzJob.Jobs.SendWxMsg.SendWxMssage(entity.obj.ID);
                var res = new ResultBase<String>()
                {
                    data = "审批会议成功",
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<String>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "审批会议失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<IHttpActionResult> GetMeetingForPad([FromBody] ObjBase<CRoomPadQuery> query)
        {


            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetMeetRoomAndInfoForPad(query.obj);

            if (list != null)
            {
                var res = new ResultBase<MeetAndRoomInfoForPad>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<MeetAndRoomInfoForPad>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议信息失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<IHttpActionResult> SignInByPhone([FromBody] ObjBase<CRoomPadQuery> query)
        {



            var service = abs.CreateConferenceRoomInterface(query.obj.phone, IPHelper.GetIPAddress);
            var (res, status) = await service.SignInCInfo(query.obj.phone, query.obj.CInfoId.ToString());

            if (res)
            {

                var data = new ObjBase<string>()
                {
                    obj = status.ToString(),
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = status.ToString(),
                    errmsg = "失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }



        /// <summary>
        /// 根据查询关键字获取会议转赠信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetTransferRecord([FromBody] ObjBase<TransferMeeting> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetTransferRecord(query.obj);

            if (list != null)
            {
                var res = new ResultBase<PageList<TransferRecord>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<PageList<TransferRecord>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议转赠记录失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 根根据用户ID查看是否有会议纪要48小时内没有上传(登陆提示,扣除积分10分)
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> CheckMinutesNotice([FromBody] ObjBase<CheckMinutesQuery> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var Notice = await service.CheckMinutesNotice(query.obj);

            if (Notice != null)
            {
                var res = new ResultBase<string>()
                {
                    data = Notice,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<string>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议纪要提示失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }
        /// <summary>
        /// 获取组织公共日历
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetOrgCalendars([FromBody] ObjBase<CalendarsMeetQuery> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetOrgCalendars(query.obj);

            if (list != null)
            {
                var res = new ResultBase<List<CalendarsMeetInfo>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<List<CalendarsMeetInfo>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取组织公共日历失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<IHttpActionResult> GetCRoomPwd([FromBody] ObjBase<CInfoPwdQuery> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var list = await service.GetCRoomPwd(query.obj);

            if (list != null)
            {
                var res = new ResultBase<List<MeetRoomPwd>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<List<MeetRoomPwd>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取密码失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }
        ///// <summary>
        ///// 获取会议须知
        ///// </summary>
        ///// <param name="query"></param>
        ///// <returns></returns>
        //[HttpPost]
        //public async Task<IHttpActionResult> UpLoadFile()
        //{
        //    var dic = User.Identity as ClaimsIdentity;
        //    var user = GetUser(dic);
        //    var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);


        //    if (list != null)
        //    {
        //        var res = new ResultBase<ConferenceNotice>()
        //        {
        //            data = list,
        //            success = true,
        //            errormsg = ""
        //        };
        //        var data = new ObjBase<ResultBase<ConferenceNotice>>()
        //        {
        //            obj = res,
        //            secret = "123"
        //        };
        //        return Content(HttpStatusCode.OK, data);
        //    }
        //    else
        //    {
        //        var result = new ErrorBase()
        //        {
        //            data = "",
        //            errmsg = "获取会议须知失败",
        //            success = false
        //        };
        //        return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
        //        {
        //            obj = result,
        //            secret = "123"
        //        }
        //        );
        //    }
        //}
        /// <summary>
        ///  会议室策略说明
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetStrategyInfo()
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var info = await service.GetStrategyInfo();

            if (info != null)
            {
                var res = new ResultBase<List<StrategyInfo>>()
                {
                    data = info,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<List<StrategyInfo>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议室策略失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }
        /// <summary>
        ///  会议室策略说明
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetStrategyInfoByID([FromBody] ObjBase<StrategyInfo> query)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var info = await service.GetStrategyInfoByID(query.obj);

            if (info != null)
            {
                var res = new ResultBase<StrategyInfo>()
                {
                    data = info,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<StrategyInfo>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议室策略失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

        /// <summary>
        /// 查看所有会议信息会议室密码
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetAllCInfoPassWord([FromBody] ObjBase<CInfoQuery> query)
        {
            PageList<MeetingInfo> list = new PageList<MeetingInfo>();
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);

            list = await service.GetAllCInfoPassWord(query.obj);



            if (list.List != null)
            {
                var res = new ResultBase<PageList<MeetingInfo>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<PageList<MeetingInfo>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议信息失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }
        [HttpPost]
        public async Task<IHttpActionResult> GetCityCInfoPassWord([FromBody] ObjBase<CInfoQuery> query)
        {
            PageList<MeetRooMPIN> list = new PageList<MeetRooMPIN>();
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            query.obj.AdminType = user.IsAdmin;
            query.obj.RegionalId = user.RegionId;
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);

            list = await service.GetCityCInfoPassWord(query.obj);



            if (list.List != null)
            {
                var res = new ResultBase<PageList<MeetRooMPIN>>()
                {
                    data = list,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<PageList<MeetRooMPIN>>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取会议信息失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }
        /// <summary>
        /// 新增组织日历信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> OrgcalendarsOrder([FromBody] ObjBase<MeetingOrder> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            bool bResult = true;
            string strError = "";
            int idd = 0;

            entity.obj.loginuserid = user.UserId;
            (bResult, strError, idd) = await service.OrgcalendarsOrder(entity.obj);

            if (bResult)
            {
                WeChatHelper helper = new WeChatHelper();
                helper.InsertWechatSchedule(idd);
            }
            var url = "";
            if (bResult)
            {

                var res = new ResultBase<String>()
                {
                    data = "日历信息创建成功",
                    success = true,
                    errormsg = "",
                    ProcessUrl = url
                };
                var data = new ObjBase<ResultBase<String>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "日历信息创建失败",
                    errmsg = strError,
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }
        /// <summary>
        /// 编辑组织日历信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> UpdateOrgcalendars([FromBody] ObjBase<MeetingOrder> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            bool bResult = true;
            string strError = "";
            int idd = 0;

            entity.obj.loginuserid = user.UserId;
            (bResult, strError, idd) = await service.UpdateOrgcalendars(entity.obj);

            if (bResult)
            {
                WeChatHelper helper = new WeChatHelper();
                helper.UpdateWechatSchedule(entity.obj.ID);
            }
            var url = "";
            if (bResult)
            {

                var res = new ResultBase<String>()
                {
                    data = "日历信息创建成功",
                    success = true,
                    errormsg = "",
                    ProcessUrl = url
                };
                var data = new ObjBase<ResultBase<String>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "日历信息创建失败",
                    errmsg = strError,
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }
        /// <summary>
        /// 取消组织日历信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> DeleteOrgcalendars([FromBody] ObjBase<MeetingOrder> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            bool bResult = true;
            string strError = "";
            int idd = 0;

            entity.obj.loginuserid = user.UserId;
            (bResult, strError, idd) = await service.DeleteOrgcalendars(entity.obj);
            if (bResult)
            {
                WeChatHelper helper = new WeChatHelper();
                helper.UpdateWechatSchedule(entity.obj.ID);
            }

            var url = "";
            if (bResult)
            {

                var res = new ResultBase<String>()
                {
                    data = "日历信息取消成功",
                    success = true,
                    errormsg = "",
                    ProcessUrl = url
                };
                var data = new ObjBase<ResultBase<String>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "日历信息取消失败",
                    errmsg = strError,
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }
        /// <summary>
        /// 获取组织日历信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IHttpActionResult> GetOrgcalendarsByID([FromBody] ObjBase<CInfoQuery> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);


            var info = await service.GetOrgcalendarsByID(entity.obj);


            if (info != null)
            {
                var res = new ResultBase<MeetingInfoSingle>()
                {
                    data = info,
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<MeetingInfoSingle>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = "获取日历信息失败",
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }
        [HttpPost]
        public async Task<IHttpActionResult> UpdatePassCode([FromBody] ObjBase<MeetingRoomOrder> entity)
        {
            var dic = User.Identity as ClaimsIdentity;
            var user = GetUser(dic);
            var service = abs.CreateConferenceRoomInterface(user.UserName, IPHelper.GetIPAddress);
            var (bResult, strError) = await service.UpdatePassCode(entity.obj);

            if (bResult)
            {
                var res = new ResultBase<String>()
                {
                    data = "修改会议室信息成功",
                    success = true,
                    errormsg = ""
                };
                var data = new ObjBase<ResultBase<String>>()
                {
                    obj = res,
                    secret = "123"
                };
                return Content(HttpStatusCode.OK, data);
            }
            else
            {
                var result = new ErrorBase()
                {
                    data = "",
                    errmsg = strError,
                    success = false
                };
                return Content(HttpStatusCode.OK, new ObjBase<ErrorBase>()
                {
                    obj = result,
                    secret = "123"
                }
                );
            }
        }

    }
}

